import { getUserDetail, changePassword } from '../service';
import { message } from 'antd';

export default {

  namespace: 'layout',

  state: {
    userInfo: {}
  },

  effects: {
    *getUserDetail({ payload, callback }, { call, put, select }) {
      const res = yield call(getUserDetail, payload);
      const { flag, data } = res.data;
      if (!flag) {
        message.warning('服务异常，请稍后重试！');
        return;
      }
      message.success(`欢迎回来，${data.name}`);
      yield put({
        type: 'savaData',
        payload: {
          userInfo: data
        }
      });
    },
    *changePassword({ payload, callback }, { call, put, select }) {
      const res = yield call(changePassword, payload);
      return res.data;
    }
  },

  reducers: {
    savaData(state, { payload }) {
      return {
        ...state,
        ...payload
      }
    },
    resetData(state, { payload }) {
      return {
        ...state,
        test: ''
      }
    }
  }

}
